package com.yunbiji.demo.controller;

import javax.annotation.Resource;

import com.yunbiji.demo.entity.CnUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yunbiji.demo.service.CnUserService;
import com.yunbiji.demo.util.NoteResult;

@Controller
@RequestMapping(value = {"cnUser","/"})
public class CnUserController {
	@Resource
	private CnUserService cnuserService;

	@RequestMapping("/change.do")
	@ResponseBody
	public NoteResult<Object> execute(String userName,String newpassword,String finalPassword){
		NoteResult<Object> result = cnuserService.changeUser(userName, newpassword, finalPassword);
		return result;
	}


	@RequestMapping("/login.do")//匹配请求
	@ResponseBody//以json结果输出
	public NoteResult<CnUser> execute1(String username, String password){
		//调用UserService处理登录请求
		System.out.println(username+","+password);
		NoteResult<CnUser> result = cnuserService.checkLogin(username,password);
		return result;
	}

	@RequestMapping("/add.do")
	@ResponseBody//以json数据格式返回数据
	public NoteResult<Object> execute2(CnUser user) {
		System.out.println("safdsasdsa"+user);
		//调用userService处理注册请求
		NoteResult<Object> result = cnuserService.addUser(user.getCnUserName(), user.getCnUserPassword(),user.getCnUserNick() );
		System.out.println(result);
		return result;
	}

}
